<template>
  <el-dialog :title="tempalteData.id  ? '编辑运费模板' : '新增运费模板'"
             :visible.sync="isShow"
             width="70%"
             @close="dialogClose"
			 append-to-body
             tip="5vh">
    <el-form ref="rules"
             :rules="rules"
             label-width="100px"
             class="demo-ruleForm"
             v-if="isShow"
             :model="tempalteData">
      <el-form-item label="供货商:"
                    prop="supplierId">
        <el-select size="mini"
                   :disabled="!bool1"
                   v-model="tempalteData.supplierId"
                   placeholder="请选择供货商">
          <el-option v-for="(item,index) in supplierlist"
                     :key="index"
                     :label="item.label"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="模板名称:"
                    prop="transName">
        <el-input style="width:180px;"
                  size="mini"
                  :disabled="!bool1"
                  placeholder="请输入运费模板名称"
                  v-model="tempalteData.transName"></el-input>
      </el-form-item>
      <el-form-item label="发货时间:"
                    prop="transTime">
        <el-select size="mini"
                   :disabled="!bool1"
                   v-model="tempalteData.transTime"
                   placeholder="请选择发货时间">
          <el-option v-for="(item,index) in deliverytime"
                     :key="index"
                     :label="item.label"
                     :value="item.value">
          </el-option>
        </el-select>
        <p class="msg"
           style="display:inline;margin-left:20px;">承诺买家付款后该时间内录入物流信息并发货，以物流公司收单信息为准<span v-if="integralDesc">元免邮费（积分商品只要打开免邮，无论此处多少钱都免邮！）</span>
        </p>
      </el-form-item>
      <el-form-item label="免邮设置:"
                    prop="freeFlag">
        <el-radio v-model="tempalteData.freeFlag"
                  :label="0"
                  :disabled="!bool1">关闭</el-radio>
        <el-radio v-model="tempalteData.freeFlag"
                  :label="1"
                  :disabled="!bool1">打开</el-radio>
        <p v-if="tempalteData.freeFlag==1"
           class="msg"
           style="width:200px;display:inline;"> 相同订单且相同运费模板下满
          <el-input-number
                    size="mini"
                    :precision="2" :step="0.1" :max="999999" :min="0.00"
                    v-model="tempalteData.freeMinPrice"
                    :disabled="!bool1"></el-input-number>
        </p>
      </el-form-item>
      <el-form-item label="计价方式:">
        <el-radio v-model="tempalteData.transType"
                  label="0"
                  :disabled="!bool1">按件数</el-radio>
        <el-radio v-model="tempalteData.transType"
                  label="1"
                  :disabled="!bool1">按重量</el-radio>
        <el-radio v-model="tempalteData.transType"
                  label="2"
                  :disabled="!bool1">按体积</el-radio>
      </el-form-item>
      <el-form-item label="运送方式:">
        <p class="msg"
           style="display:inline">除指定地区外，其他地区的运费采用"默认运费"</p>
        <el-form-item>
          <el-checkbox v-model="tempalteData.transExpress"
                       :checked="true"
                       :disabled="!bool1">快递</el-checkbox>
          <!-- 快递运送方式 -->
          <div v-if="tempalteData.transExpress">
            <el-form :inline="true"
                     ref="defaultDeliveryRules"
                     :rules="defaultDeliveryRules"
                     :model="defaultDelivery"
                     class="demo-form-inline">
              <el-form-item label="默认运费:"
                            prop="trans_weight">
                <el-input size="mini"
                          :disabled="!bool1"
                          style="width:100px;"
                          v-model="defaultDelivery.trans_weight"></el-input>
              </el-form-item>
              <p class="line msg">{{unit}}内</p>
              <el-form-item prop="trans_fee">
                <el-input size="mini"
                          :disabled="!bool1"
                          style="width:100px;"
                          v-model="defaultDelivery.trans_fee"></el-input>
              </el-form-item>
              <p class="line msg">¥,每增加</p>
              <el-form-item prop="trans_add_weight">
                <el-input size="mini"
                          style="width:100px;"
                          :disabled="!bool1"
                          v-model="defaultDelivery.trans_add_weight"></el-input>
              </el-form-item>
              <p class="line msg">{{unit}},增加运费</p>
              <el-form-item prop="trans_add_fee">
                <el-input size="mini"
                          style="width:120px;"
                          :disabled="!bool1"
                          v-model="defaultDelivery.trans_add_fee"></el-input>
              </el-form-item>
              <p class="line msg">¥</p>
            </el-form>
            <div style="width:100%;height:20px;"> </div>
            <avue-crud ref="crud"
                       :option="expressageOption"
                       :data="expressageData"
                       @row-update="addUpdate">
              <template slot="menuLeft"
                        v-if="bool1">
                <el-button @click="addRow"
                           type="primary"
                           size="mini">添加指定区域城市设置运费</el-button>
              </template>
              <template slot-scope="scope"
                        slot="menu">
                <el-button size="mini"
                           type="primary"
                           @click="editCity(scope)">编辑地区</el-button>
                <el-button size="mini"
                           type="primary"
                           @click="delRow(scope,'yf')">删除</el-button>
              </template>
            </avue-crud>

          </div>

          <el-checkbox v-model="tempalteData.postalRulesSwitch"
                       :disabled="!bool1">指定条件包邮</el-checkbox>

          <div v-if="tempalteData.postalRulesSwitch">
            <!-- 包邮 -->
            <avue-crud ref="exemcrud"
                       :option="exemptionOption"
                       :data="exemptionData"
                       @row-update="addUpdate">
              <template slot="menuLeft"
                        v-if="bool">
                <el-button @click="addexemptionRow"
                           type="primary"
                           size="mini">添加指定区域城市设置包邮</el-button>
              </template>
              <template slot-scope="scope"
                        slot="menu">
                <el-button size="mini"
                           type="primary"
                           @click="addCity(scope)">编辑地区</el-button>
                <el-button size="mini"
                           type="primary"
                           @click="delRow(scope,'by')">删除</el-button>
              </template>
            </avue-crud>

          </div>

        </el-form-item>
      </el-form-item>
      <el-form-item v-if="bool1">
        <el-button type="primary"
                   @click="onSubmit('rules','defaultDeliveryRules')">保存</el-button>
      </el-form-item>
    </el-form>
    <change-area ref="changeArea"
                 @citysData="getcityData"></change-area>
  </el-dialog>
</template>
<script>
import {
  addfreightemplate,
  editfreightemplate,
  getsupplierlist
} from '@/api/base/goods/addGoods';
import changeArea from './changeArea';
import {
		isInteger,isIntegerFixTwo,testWeightAndVolue,isInteger0
	} from '@/util/util'
import {mapGetters} from "vuex";
const deliverytime = [
  {
    label: '12小时内',
    value: '12'
  },
  {
    label: '24小时内',
    value: '24'
  },
  {
    label: '48小时内',
    value: '48'
  },
  {
    label: '72小时内',
    value: '72'
  },
  {
    label: '5天内',
    value: '120'
  },
  {
    label: '7天内',
    value: '168'
  },
  {
    label: '15天内',
    value: '360'
  },
  {
    label: '30天内',
    value: '720'
  },
  {
    label: '45天内',
    value: '1000'
  }
];
export function testName(rule, value, callback) {
  if(value!=0){
    if (!value) {
      return callback(new Error('输入不可以为空'));
    }
  }
  setTimeout(() => {
    // let newValue= value.replace(/\s*/g,"");
    let empty=/^\S.*\S$/
    const re = /^[\u4e00-\u9fa5a-zA-Z0-9` ~!@#^&*()_\-+=<>:"{}|,;'·~！@#……&*（）—\-+={}|《》？：“”【】、；‘'，。.]+$/;  //这是校验不包含特殊符号
    const testIsContainSpec = re.test(value);
    const testEmpty = empty.test(value);
    if(value.length < 2 || value.length>30){
      callback(new Error('长度为2-30位'));
    }else if (!testEmpty) {
      callback(new Error('不能输入空格'));
    }else if (!testIsContainSpec) {
      callback(new Error('不能输入特殊字符'));
    }else {
      callback();
    }

  }, 0);
}
export default {
  components: {
    changeArea
  },
  data () {
    return {
      transTypeBefore: 0,
      storeId:'',//仅仅是用于传值
      integralDesc:false,//积分商品免邮描述
      isFirst:true,//是否是第一次进入这个界面
      areadata:[],
      unit:"件",//默认位置 计价方式单位 件,kg,m3
      deliverytime,
	  btnloading: false,
      isShow: false,
      area: false,
      bool: true,
      bool1: true,
      cityflg: '1',
      supplierlist: [],
      tempalteData: {
        supplierId: '',//供货商
        transName: '',//模板名称
        transTime: '',//发货时间
        freeFlag: 0,//免邮设置
        freeMinPrice: 0,//免邮设置打开输入框
        transType: '0',//计价方式
        postalRulesSwitch: false,//指定条件包邮
        transExpress: false,//快递运送方式
        transExpressInfo: [],
        transPostalRules: {
          transExpressInfo: []
        }
      },//运费模板弹窗数据
      rules: {
        transName: [
          {
            required:true,
            validator:testName
          }
        ],
        transTime: [
          { required: true, message: '请选择发货时间', trigger: 'change' }
        ],
      },
      defaultDelivery: {
        city_id: '-1',
        city_name: '全国',
        trans_weight: '',
        trans_fee: '',
        trans_add_weight: '',
        trans_add_fee: ''
      },
      defaultDeliveryRules: {
        trans_weight: [
          {
          required: true, message: '请输入首件', trigger: 'blur'
           },
          {
            validator: isInteger0,
            trigger: 'blur'
              }
        ],
        trans_fee: [
          {
          required: true, message: '请输入首件价钱', trigger: 'blur'
           },
           {
             validator: isIntegerFixTwo,
             trigger: 'blur'
           }
        ],
        trans_add_weight: [
          { required: true, message: '请输入增加件数', trigger: 'blur' },
          {
              validator: isInteger0,
              trigger: 'blur'
            }
        ],
        trans_add_fee: [
          { required: true, message: '请输入超件价钱', trigger: 'blur' },
          {
              validator: isIntegerFixTwo,
              trigger: 'blur'
            }
        ]
      },
      expressageIndex: 0,
      expressageData: [],//快递选择地区回来的数据
      expressageOption: {
        keyId: 'id',
        addBtn: false,
        delBtn: false,
        editBtn: false,
        addRowBtn: false,
        cellBtn: false,
        cancelBtn: false,
        refreshBtn: false,
        columnBtn: false,
        menu: true,
        border: true,
		menuWidth: 180,
        align: 'center',
        headersAlign: 'center',
        column: [
          {
            label: '运送地区',
            prop: 'city_name',
            type: 'textarea',
            cell: false,
            width: 250,
          },
          {
            width: 160,
            label: '首件(件)',
            prop: 'trans_weight',
            cell: true,
			placeholder: '请输入',
            rules:[
              {
                required: true,
                message: "请输入首件，例（1）",
                trigger: "blur"
              }
            ]
          },
          {
            width: 160,
            label: '首费(￥)',
            prop: 'trans_fee',
            cell: true,
			placeholder: '请输入',
            rules:[
              {
                required: true,
                message: "请输入首费，例（0.00）",
                trigger: "blur"
              }
            ]
          },
          {
            width: 160,
            label: '续件(件)',
            prop: 'trans_add_weight',
            cell: true,
			placeholder: '请输入',
            rules:[
              {
                required: true,
                message: "请输入续件，例（0.00）",
                trigger: "blur"
              }
            ]
          },
          {
            width: 160,
            label: '续费(￥)',
            prop: 'trans_add_fee',
            cell: true,
			placeholder: '请输入',
            rules:[
              {
                required: true,
                message: "请输入续费，例（0.00）",
                trigger: "blur"
              }
            ]
          }
        ]
      },
      exemptionData: [],
      exemptionOption: {
        keyId: 'id',
        addBtn: false,
        editBtn: false,
        delBtn: false,
        addRowBtn: false,
        cellBtn: false,
        cancelBtn: false,
        refreshBtn: false,
        columnBtn: false,
        menu: true,
        border: true,
        align: 'center',
        headersAlign: 'center',
        column: [
          {
            label: '运送地区',
            prop: 'city_name',
            type: 'textarea',
            cell: false,
          },
          {
            width: 150,
            label: '选择运输方式',
            type: 'select',
            prop: 'modeDelivery',
            dicData: [
              {
                label: '快递',
                value: '1'
              }
            ],
            cell: true,
			placeholder: '请输入'
          },
          {
            width: 150,
            label: '设置包邮条件（满x/件包邮）',
            prop: 'conditionalData',
            cell: true,
			placeholder: '请输入'
          }
        ]
      },
      expresseditdata: [],
      exemptioneditdata: []
    }
  },
  props: {
    viewData: {
      type: Object,
      default () {
        return {}
      }
    },
    editData: {
      type: Object,
      default () {
        return {}
      }
    },
    whichType:{
    	type:String,
	    default:''
    },
  },
  computed: {
    ...mapGetters(["permission", 'userInfo']),
    permissionList() {
      return {

      };
    },
  },
  watch: {
    'isShow' (e) {
      if (!e) {
        this.bool = true;
        this.bool1 = true;
        this.expressageOption.menu = true;
        this.exemptionOption.menu = true;
      }
    },
    'viewData' (e) {
      console.log(e)
      this.bool = false;
      this.bool1 = false;
      this.tempalteData.supplierId = e.supplierId + '';
      this.tempalteData.transName = e.transName;
      this.tempalteData.transTime = e.transTime + '';
      this.tempalteData.freeFlag = e.freeFlag;
      this.tempalteData.transType = e.transType + '';
      this.transTypeBefore = e.transType;
      this.tempalteData.freeMinPrice=e.freeMinPrice;
      this.tempalteData.postalRulesSwitch = e.postalRulesSwitch;
      this.tempalteData.transExpress = Boolean(e.transExpress);
      if (e.transExpress) {
        this.expressageOption.menu = false;
        this.defaultDelivery = e.transExpressInfo[0];
        this.expressageData = e.transExpressInfo.slice(1);
      }
      if (e.postalRulesSwitch) {
        this.exemptionOption.menu = false;
        this.exemptionData = e.transPostalRules.transExpressInfo;
      }
    },
    'editData' (e) {
      console.log(e)
      this.tempalteData.supplierId = e.supplierId + '';
      this.tempalteData.transName = e.transName;
      this.tempalteData.transTime = e.transTime + '';
      this.tempalteData.freeFlag = e.freeFlag;
      this.tempalteData.transType = e.transType + '';
      this.transTypeBefore = e.transType;
      this.tempalteData.postalRulesSwitch = e.postalRulesSwitch;
      this.tempalteData.freeMinPrice=e.freeMinPrice;
      this.tempalteData.transExpress = Boolean(e.transExpress);
      this.tempalteData.id = e.id;
      if (e.transExpress) {
        this.defaultDelivery = e.transExpressInfo[0];
        this.expressageData = e.transExpressInfo.slice(1).map(item => {
          return Object.assign(item, { $cellEdit: true })
        });
      }
      if (e.postalRulesSwitch) {
        this.exemptionData = e.transPostalRules.transExpressInfo.map(item => {
          return Object.assign(item, { $cellEdit: true })
        });
      }
    },
    'tempalteData.transType'(val){
      //unit:"件",//默认位置 计价方式单位 件,kg,m3
      if(this.transTypeBefore != val){
          this.resetDefaultDelivery();
      }else{
          this.transTypeBefore = val;
      }
      if(val == 0){//按件数
        this.unit="件";
        this.expressageOption.column[1].label="首件（件）";
        this.expressageOption.column[3].label="续件（件）";
		this.defaultDeliveryRules.trans_weight[0].message='请输入首件'
		this.defaultDeliveryRules.trans_weight[1].validator = isInteger0
		this.defaultDeliveryRules.trans_fee[0].message='请输入首件价格'
		this.defaultDeliveryRules.trans_add_weight[0].message='请输入增加件数'
		this.defaultDeliveryRules.trans_add_weight[1].validator = isInteger0
		this.defaultDeliveryRules.trans_add_fee[0].message='请输入超件价格'
        this.exemptionOption.column[2].label="设置包邮条件（满x/件包邮）";
      }else if(val==1){//按重量
        this.unit="kg";
        this.expressageOption.column[1].label="首重（kg）";
        this.expressageOption.column[3].label="续重（kg）";
		this.defaultDeliveryRules.trans_weight[0].message='请输入首重'
		this.defaultDeliveryRules.trans_weight[1].validator = testWeightAndVolue
		this.defaultDeliveryRules.trans_fee[0].message='请输入首重价格'
		this.defaultDeliveryRules.trans_add_weight[0].message='请输入增加重量'
		this.defaultDeliveryRules.trans_add_weight[1].validator = testWeightAndVolue
		this.defaultDeliveryRules.trans_add_fee[0].message='请输入超重价格'
        this.exemptionOption.column[2].label="设置包邮条件（低于x/kG包邮）";
      }else if(val==2){//按体积
        this.unit="dm³";
        this.expressageOption.column[1].label="首体积（dm³）";
        this.expressageOption.column[3].label="续体积（dm³）";
		this.defaultDeliveryRules.trans_weight[0].message='请输入首体积'
		this.defaultDeliveryRules.trans_weight[1].validator = testWeightAndVolue
		this.defaultDeliveryRules.trans_fee[0].message='请输入首体积价格'
		this.defaultDeliveryRules.trans_add_weight[0].message='请输入增加体积'
		this.defaultDeliveryRules.trans_add_weight[1].validator = testWeightAndVolue
		this.defaultDeliveryRules.trans_add_fee[0].message='请输入超出体积价格'
        this.exemptionOption.column[2].label="设置包邮条件（低于x/dm³包邮）";
      }
    }
  },
  created () {
    this.getsupplierlist();
    //判断当前用户是否包含积分卖家角色
    if(this.userInfo.roleIds.indexOf(6)!=-1){
      this.integralDesc=true;
    }
  },
  methods: {
    dialogClose(){
      //清除数据
      this.tempalteData= {
        supplierId: '',//供货商
        transName: '',//模板名称
        transTime: '',//发货时间
        freeFlag: 0,//免邮设置
        freeMinPrice: 0,//免邮设置打开输入框
        transType: '0',//计价方式
        postalRulesSwitch: false,//指定条件包邮
        transExpress: false,//快递运送方式
        transExpressInfo: [],
        transPostalRules: {
          transExpressInfo: []
        }
      }
      this.resetDefaultDelivery();
      this.exemptionData=[],
      this.expressageData=[],
      this.$refs['rules'].resetFields();
      // this.$refs['defaultDeliveryRules'].resetFields();
    },
    //重置默认的快递运费规则
    resetDefaultDelivery(){
      //如果是编辑界面，并且是第一次打开需要回显数据所以不清空该数据
      if(this.isFirst==true) {
        this.isFirst = false;
        this.$nextTick(()=>{
            this.$refs["defaultDeliveryRules"].clearValidate();
        });
          this.$refs['defaultDeliveryRules'].resetFields();
        return;
      }
      this.defaultDelivery={
        city_id: '-1',
        city_name: '全国',
        trans_weight: '',
        trans_fee: '',
        trans_add_weight: '',
        trans_add_fee: ''
      },
      this.exemptionData=[],
      this.expressageData=[],
      this.$nextTick(()=>{
          this.$refs["defaultDeliveryRules"].clearValidate();
      });
      this.$refs['rules'].resetFields();
      // this.$refs['defaultDeliveryRules'].resetFields();
    },
    getsupplierlist () {
      getsupplierlist(this.storeId).then(res => {
        if (res.data.code == 200) {
          //供货商列表
          this.supplierlist = res.data.data.map(item => {
            return { label: item.title, value: item.id }
          })
          this.supplierlist.unshift({ label: '自供货', value: '' })
          console.log(this.supplierlist)
        }
      })
    },

    getcityData (e) {
      //接收数据
      if (this.cityflg == '1') {
        this.expressageData[this.expressageIndex].city_name = e.checkeddataStr.join(',');
        this.expressageData[this.expressageIndex].city_id = e.checkeddataIds.join(',');
      } else {
        this.exemptionData[this.expressageIndex].city_name = e.checkeddataStr.join(',');
        this.exemptionData[this.expressageIndex].city_id = e.checkeddataIds.join(',');
      }

    },
    open () {
      this.isFirst=true;
      this.isShow = true;
      if(this.viewData.id){
          this.isFirst=true;
      }
      else {
          this.isFirst=false;
      }
    },
    close () {
      this.isShow = false
    },
    addRow () {
      this.$refs.crud.rowCellAdd({
        city_name: '',
        trans_weight: '',
        trans_fee: '',
        trans_add_weight: '',
        trans_add_fee: '',
        city_id: ''
      });
    },
    addexemptionRow () {
      this.$refs.exemcrud.rowCellAdd({
        city_name: '',
        modeDelivery: '',
        packetType: this.tempalteData.transType,
        conditionalData: '',
        city_id: ''
      });
    },
	//添加指定区域城市设置运费
    editCity (e) {
      this.expressageIndex = e.index;
      this.cityflg = '1';
      let data = this.expressageData[e.index].city_id.split(',');
      if(this.expressageData[e.index] == ''){
        this.$refs.changeArea.open();
        this.$refs.changeArea.setChecked([])
      }else{
        //编辑地区
        this.$refs.changeArea.open();
        this.$refs.changeArea.setChecked(data)
      }

    },
	//添加指定区域城市设置包邮
    addCity (e) {
      this.expressageIndex = e.index;
      this.cityflg = '2';
	  let data = this.exemptionData[e.index].city_id.split(',');
	  if(this.exemptionData[e.index] == ''){
	    this.$refs.changeArea.open();
	    this.$refs.changeArea.setChecked([])
	  }else{
	    //编辑地区
	    this.$refs.changeArea.open();
	    this.$refs.changeArea.setChecked(data)
	  }
      // this.$refs.changeArea.open();
    },
    //真正的新增逻辑
    onSubmitTrue(c,d){
      //若干每天写相同运费模板下满**包邮，则为0.00
      if(!this.tempalteData.freeMinPrice){
        this.tempalteData.freeMinPrice=0.00;
      }

      if (c && d) {
        this.tempalteData.transExpress ? this.tempalteData.transExpress = 1 : this.tempalteData.transExpress = '';
        this.expressageData.unshift(this.defaultDelivery);
        let data = this.expressageData.map(item => {
          return {
            city_name: item.city_name,
            trans_weight: item.trans_weight,
            trans_fee: item.trans_fee,
            trans_add_weight: item.trans_add_weight,
            trans_add_fee: item.trans_add_fee,
            city_id: item.city_id
          }
        })
        this.tempalteData.transExpressInfo = this.tempalteData.transExpressInfo.concat(data);
        this.tempalteData.transExpressInfo = JSON.stringify(this.tempalteData.transExpressInfo);
        //临时代码用来找某种情况出现的错误！
        if(this.tempalteData.transExpressInfo.indexOf("Object]")!=-1){
          this.$message.error("请刷新重试！");
          return;
        }
        if (this.tempalteData.postalRulesSwitch) {
          let data = this.exemptionData.map((item) => {
            return {
              city_name: item.city_name,
              modeDelivery: item.modeDelivery,
              packetType: this.tempalteData.transType,
              conditionalData: item.conditionalData,
              city_id: item.city_id
            }
          })
          this.tempalteData.transPostalRules.transExpressInfo = this.tempalteData.transPostalRules.transExpressInfo.concat(data);
          this.tempalteData.transPostalRules = JSON.stringify(this.tempalteData.transPostalRules);
        }
        console.log(this.whichType);
        if(this.whichType == "addTransport"){
          addfreightemplate(this.tempalteData).then(res => {
            this.expressageData.shift()
            if (res.data.code == 200) {
                this.$refs['defaultDeliveryRules'].resetFields();
				setTimeout(() => {
					this.btnloading = false;
				}, 1000)
              this.$message.success("新增成功")
              this.$emit('success', true)
              this.close()
            }
          })
        }
        else if(this.whichType == "editTransport"){
          editfreightemplate(this.tempalteData).then(res => {
            this.expressageData.shift()
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "保存成功!"
              });
				setTimeout(() => {
					this.btnloading = true;
				}, 1000)
              this.$emit('success', true)
              this.close()
            }
            else {
              this.$message({
                type: "error",
                message: res.data.message
              });
            }
          })
        }
      }
    },
    onSubmit (a, b) {
      let c = false;
      this.$refs[a].validate((val) => {
        c = val;
      });
      if(!this.tempalteData.transExpress && !this.tempalteData.postalRulesSwitch){
        this.$message({
          type: "error",
          message: "请先选择运送方式"
        });
        return;
      }
      if(!this.tempalteData.transExpress && this.tempalteData.postalRulesSwitch){
        this.$message({
          type: "error",
          message: "请先选择运送方式快递规则！"
        });
        return;
      }
      var flg = true;
      var str = "";
      //校验运费规则
      for(var i=0;i<this.$refs.crud.list.length;i++){
        var item = this.$refs.crud.list[i];
        var trans_weight = item.trans_weight;
        var trans_fee = item.trans_fee;
        var trans_add_weight = item.trans_add_weight;
        var trans_add_fee = item.trans_add_fee;
        var aa = this.isInteger0(trans_weight);
        var bb = this.isIntegerFixTwo0(trans_fee);
        var dd = this.isInteger0(trans_add_weight);
        var ff = this.isIntegerFixTwo0(trans_add_fee);
        if(aa!="0"){
          flg = false;
          str = aa;
          break;
        }
        if(bb!="0"){
          flg = false;
          str = bb;
          break;
        }
        if(dd!="0"){
          flg = false;
          str = dd;
          break;
        }
        if(ff!="0"){
          flg = false;
          str = ff;
          break;
        }
      }
      if(!flg){
        this.$message({
          type: "error",
          message: '添加指定区域城市设置运费值'+str
        });
        return;
      }
      //校验包邮规则
      if(this.tempalteData.postalRulesSwitch){
        let postRelusFlag=0;
        if(this.exemptionData.length==0){
          postRelusFlag=1;
          this.$message.error("请填写包邮规则！")
        }
        for(let i=0;i<this.exemptionData.length;i++){
          if(this.exemptionData[i].city_id==""){
            postRelusFlag=1
            this.$message.error("条件包邮运送地区必填！")
            break
          }
          let modeDelivery = this.exemptionData[i].modeDelivery;
          if (modeDelivery == "") {
            postRelusFlag=1
            this.$message.error("运输方式不能为空！")
            break
          }
          let exception=this.exemptionData[i].conditionalData;
          if(exception==""){
            postRelusFlag=1
            this.$message.error("包邮条件不能为空！")
            break
          }else if(this.tempalteData.transType==0){ //按件数
            const re = /^\+?[1-9][0-9]*$/;
            const rsCheck = re.test(exception);
            if(!rsCheck){
              this.$message.error("请填写正整数")
              postRelusFlag=1;
              break
            }
          }else {//按体积 或重量
            const re1 = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/;
            const rsCheck = re1.test(exception);
            if(!rsCheck){
              this.$message.error("请填写数字，保留两位小数！")
              break;
            }
          }
        }
        if(postRelusFlag==1){
          return;
        }
      }
      console.log(this.defaultDelivery);
      this.$refs[b].validate((lid) => {
          this.onSubmitTrue(c,lid);
      });

    },
    delRow (data,str) {
      // 删除行操作
      console.log(data)
      console.log(str)
      let index = data.index;
      if(str == 'yf'){
        //删除的是设置运费
        this.expressageData.splice(index,1)
      }else{
        //删除的是包邮
        this.exemptionData.splice(index,1)
      }

    },
    handleChange () {
      //选择地区处理事件
    },
    addUpdate () {

    },
    isInteger0(value) {
      if (!value) {
        return '输入不可以为空';
      }
      var val = this.tempalteData.transType;
      if(val == 0) {//按件数
        if (!Number(value)) {
          return '首件/续件为大于0的整数';
        } else {
          const re = /^\+?[1-9][0-9]*$/;
          const rsCheck = re.test(value);
          if (!rsCheck) {
            return '首件/续件为大于0的整数';
          }else{
            return '0'
          }
        }
      }else{
        if (!Number(value)) {
          return '首/续/重/体积必须是大于0的数字(保留两位小数)';
        } else {
          const re1 = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/;
          const rsCheck = re1.test(value);
          if (!rsCheck) {
            return '首/续/重/体积必须是大于0的数字(保留两位小数)';
          }else{
            return '0'
          }

        }
      }

    },

    isIntegerFixTwo0(value) {
      if (value!=0) {
          if(!value){
              return '输入不可以为空';
          }
      }
        const re1 = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/;
        const rsCheck = re1.test(value);
        if (!rsCheck) {
            return '必须是大于或者等于0的数字(保留两位小数)';
        }else{
            return '0'
        }
    }
  }
}
</script>
<style scoped>
.fromRow {
  display: flex;
  justify-content: flex-start;
  width: 80%;
  padding: 10px 0;
  align-items: center;
}
.el-textarea {
  width: 80%;
}
.msg {
  font-size: 10px;
  color: #999;
}
.price {
  width: 200px;
  margin-right: 20px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 400px;
}
.cardipt {
  width: 200px;
}
.line {
  display: inline;
}
</style>